package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.health.dao.ReportMemberDao;
import com.itheima.health.service.ReportMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service(interfaceClass = ReportMemberService.class)
@Transactional
public class ReportMemberServiceImpl implements ReportMemberService{
    @Autowired
    ReportMemberDao reportMemberDao;
    @Override
    public List<Map<String, Object>> getMemberBySex() {

        List<Map<String,Object>> list=new ArrayList<>();

        Map<String,Object> map1=new HashMap<>();

        String sexId=1+"";
        Integer memberNum1=reportMemberDao.getMemberBySex(sexId);
        map1.put("name","男");
        map1.put("value",memberNum1);
        list.add(map1);

        Map<String,Object> map2=new HashMap<>();
        String sexId2=2+"";
        Integer memberNum2=reportMemberDao.getMemberBySex(sexId2);
        map2.put("name", "女");
        map2.put("value", memberNum2);
        list.add(map2);
        return list;
    }

    @Override
    public List<Map<String, Integer>> getMemberByAge() {
        List<Map<String,Integer>>age=new ArrayList<>();
        HashMap<String,Integer> hm = new HashMap();
        int count= reportMemberDao.getMemberByAge(0,18);
        hm.put("count1",count);
        int count2= reportMemberDao.getMemberByAge(18,30);
        hm.put("count2",count2);
        int count3= reportMemberDao.getMemberByAge(30,45);
        hm.put("count3",count3);
        int count4= reportMemberDao.getMemberByAge(45,150);
        hm.put("count4",count4);
        age.add(hm);
        return age;
    }
}
